package n64;

import java.awt.Color;

public class VI {

	public static final int VI_STATUS_REG = 0;
	public static final int VI_ORIGIN = 1;
	public static final int VI_WIDTH_REG = 2;
	public static final int VI_INTR_REG = 3;
	public static final int VI_CURRENT_REG = 4;
	public static final int VI_TIMING_REG = 5;
	public static final int VI_V_SYNC_REG = 6;
	public static final int VI_H_SYNC_REG = 7;
	public static final int VI_LEAP_REG = 8;
	public static final int VI_H_START_REG = 9;
	public static final int VI_V_START_REG = 10;
	public static final int VI_V_BURST_REG = 11;
	public static final int VI_X_SCALE_REG = 12;
	public static final int VI_Y_SCALE_REG = 13;
	
	/**
	 * 0x4400000          ; VI_STATUS_REG
	 * 0x4400004          ; VI_ORIGIN
	 * 0x4400008          ; VI_WIDTH_REG
	 * 0x440000C          ; VI_INTR_REG
	 * 0x4400010          ; VI_CURRENT_REG
	 * 0x4400014          ; VI_TIMING_REG
	 * 0x4400018          ; VI_V_SYNC_REG
	 * 0x440001C          ; VI_H_SYNC_REG
	 * 0x4400020          ; VI_LEAP_REG
	 * 0x4400024          ; VI_H_START_REG
	 * 0x4400028          ; VI_V_START_REG
	 * 0x440002C          ; VI_V_BURST_REG
	 * 0x4400030          ; VI_X_SCALE_REG
	 * 0x4400034          ; VI_Y_SCALE_REG
	 */
	public static final int REG[] = new int[14];
	
	public static Color decodeRGBA8888(final int rgba) {
		
		int r = (rgba >> 24) & 0x000000FF;
		int g = (rgba >> 16) & 0x000000FF;
		int b = (rgba >> 8) & 0x000000FF;
		int a = (rgba >> 0) & 0x000000FF;
		
		return new Color(r,g,b,a);
	}
	
	public static int readWord(final int address) {
		
		//System.out.println("logged VI read: " + address);
		
		if(address >= 0x00000000 && address <= 0x00000034) {
			return REG[address >> 2];
		}
		
		return -1;
	}
	
	public static void writeWord(final int word, final int address) {
		
		//System.out.println("logged VI write: " + word + " @ " + address);
		
		if(address >= 0x00000000 && address <= 0x00000034) {
			REG[address >> 2] = (word & 0xFFFFFFFF);
		}
	}
}
